//package com.msj.goods.controller;
//
//import com.baomidou.mybatisplus.mapper.EntityWrapper;
//import com.dingtalk.api.DefaultDingTalkClient;
//import com.dingtalk.api.DingTalkClient;
//import com.dingtalk.api.request.OapiUserGetRequest;
//import com.dingtalk.api.request.OapiUserGetuserinfoRequest;
//import com.dingtalk.api.response.OapiUserGetResponse;
//import com.dingtalk.api.response.OapiUserGetuserinfoResponse;
//import com.msj.goods.common.constants.URLConstant;
//import com.msj.goods.common.web.base.JsonResult;
//import com.msj.goods.entity.Emp;
//import com.msj.goods.service.EmpService;
//import com.msj.goods.utils.AccessTokenUtil;
//import com.msj.goods.utils.ServiceResult;
//import com.taobao.api.ApiException;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.*;
//
//import java.util.HashMap;
//import java.util.Map;
//
//*
// * @author sun li
// * @Date 2018/11/5 9:02
// * @Description
//
//
//
//
//@RestController
//@RequestMapping("/empp")
//@Api(description = "员工信息")
//public class EmpController {
//
//    @Autowired
//    private EmpService empService;
//
//    @RequestMapping("/list")
//    @ApiOperation(value="查询所有员工", notes="查询查询所有员工列表")
//    @PostMapping
//    public JsonResult selectAll(){
//        EntityWrapper<Emp> ew1 = new EntityWrapper<>();
//
//        return  JsonResult.success(empService.selectList(ew1), "查询成功");
//    }
//
//*
//     * 欢迎页面,通过url访问，判断后端服务是否启动
//     *
//
//
//    @RequestMapping(value = "/welcome", method = RequestMethod.GET)
//    public String welcome() {
//        return "welcome";
//    }
//
//*
//     * 钉钉用户登录，显示当前登录用户的userId和名称
//     *
//     * @param requestAuthCode 免登临时code
//
//
//
//
//    @RequestMapping(value = "/login", method = RequestMethod.POST)
//    public ServiceResult login(@RequestParam(value = "authCode") String requestAuthCode) {
//        //获取accessToken,注意正是代码要有异常流处理
//        String accessToken = AccessTokenUtil.getToken();
//
//        //获取用户信息
//        DingTalkClient client = new DefaultDingTalkClient(URLConstant.URL_GET_USER_INFO);
//        OapiUserGetuserinfoRequest request = new OapiUserGetuserinfoRequest();
//        request.setCode(requestAuthCode);
//        request.setHttpMethod("GET");
//
//        OapiUserGetuserinfoResponse response;
//        try {
//            response = client.execute(request, accessToken);
//        } catch (ApiException e) {
//            e.printStackTrace();
//            return null;
//        }
//        //3.查询得到当前用户的userId
//        // 获得到userId之后应用应该处理应用自身的登录会话管理（session）,避免后续的业务交互（前端到应用服务端）每次都要重新获取用户身份，提升用户体验
//        String userId = response.getUserid();
//
//        String userName = getUserName(accessToken, userId);
//        System.out.println(userName);
//        //返回结果
//        Map<String, Object> resultMap = new HashMap<>();
//        resultMap.put("userId", userId);
//        resultMap.put("userName", userName);
//        ServiceResult serviceResult = ServiceResult.success(resultMap);
//        return serviceResult;
//    }
//
//
//*
//     * 获取用户姓名
//     *
//     * @param accessToken
//     * @param userId
//     * @return
//
//
//
//
//    private String getUserName(String accessToken, String userId) {
//        try {
//            DingTalkClient client = new DefaultDingTalkClient(URLConstant.URL_USER_GET);
//            OapiUserGetRequest request = new OapiUserGetRequest();
//            request.setUserid(userId);
//            request.setHttpMethod("GET");
//            OapiUserGetResponse response = client.execute(request, accessToken);
//            return response.getName();
//        } catch (ApiException e) {
//            e.printStackTrace();
//            return null;
//        }
//    }
//}
